<template>
  <view class="order-page">
    <!-- 导航栏 -->
    <!-- <uni-nav-bar fixed statusBar>
      <template #default>
        <view class="title">
          <wd-icon v-if="isConnected" name="wifi" size="42rpx" color="#06C662"></wd-icon>
          <wd-icon v-else name="wifi-error" size="36rpx" color="#fa4350"></wd-icon>
          {{ `${userStore.userInfo?.name || ''}(${userStore.userInfo?.env_company || ''})` }}
        </view>
      </template>
      <template #left>
        <view class="logout" @click="logout">
          <wd-icon name="logout" size="40rpx" color="#ED1C24"></wd-icon>
        </view>
      </template>
    </uni-nav-bar> -->
    <custom-navbar></custom-navbar>
    <!-- 主体 -->
    <view class="body">
      <!-- 蓝牙工具栏 -->
      <tw-bluetooth-tool></tw-bluetooth-tool>
      <order-template-1></order-template-1>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
import { onPullDownRefresh, onLoad } from '@dcloudio/uni-app'
import { isNetWork } from '@/utils/system'
import { postOrderListAPI } from '@/api/apis'
import { useUserStore, useOrderStore } from '@/stores/'
const userStore = useUserStore()
const orderStore = useOrderStore()
// import { useMessage } from 'wot-design-uni'
// const logoutDialog = useMessage('logout-dialog')
// 退出登录
// function logout() {
//   logoutDialog
//     .confirm({
//       title: '提示',
//       msg: '确定要退出登录吗？',
//       confirmButtonProps: { type: 'error' },
//     })
//     .then(() => {
//       console.log('退出')
//       userStore.clear()
//       uni.reLaunch({ url: '/pages/login/login' })
//     })
//     .catch((error) => {
//       console.log(error)
//     })
//   // uni.showModal({
//   //   title: '提示',
//   //   content: '确定要退出登录吗？',
//   //   success: function (res) {
//   //     if (res.confirm) {
//   //       console.log('用户点击确定')
//   //     } else if (res.cancel) {
//   //       console.log('用户点击取消')
//   //     }
//   //   },
//   // })
// }
// 网络状态
const isConnected = ref(false)

// 获取工单列表
async function postOrderList() {
  const res = await postOrderListAPI()
  orderStore.setOrderList(res.records)
}

onLoad(async () => {
  isConnected.value = await isNetWork()
  // console.log('res:', res)
  if (isConnected.value && userStore.actionType === 'online') {
    await postOrderList()
  }
  uni.onNetworkStatusChange((res) => {
    isConnected.value = res.isConnected
  })
})
// onShow(() => {
//   test.value = getApp().globalData.text
//   getApp().globalData.text = 222
// })
onPullDownRefresh(async () => {
  if (isConnected.value && userStore.actionType === 'online') {
    await postOrderList()
  }
  setTimeout(function () {
    uni.stopPullDownRefresh()
  }, 1000)
})
</script>

<style lang="scss" scoped>
.order-page {
  // height: calc(100vh - 48px - var(--window-top));
  // height: calc(100vh - 48px - var(--window-top) - constant(safe-area-inset-bottom));
  // height: calc(100vh - 48px - var(--window-top) - env(safe-area-inset-bottom));
  // overflow: auto;
  // .order-page::-webkit-scrollbar {
  //   display: none !important;
  //   width: 0 !important;
  //   height: 0 !important;
  //   -webkit-appearance: none;
  //   background: transparent;
  // }
  // .title {
  //   @include flex-box-set(center);
  //   width: 100%;
  //   font-size: initial;
  // }
  .body {
    padding: 12px;
  }
}
</style>
